<?php
require_once("BaseSnack.php");
require_once("MysqlConn.php");

class Snack_R extends BaseSnack {
   public function queryInfo() {
      if($this->id != null && is_int($this->id)) {
         $query = "select * from snacks where SNA_ID=$this->id;";
         $conn = new MysqlConn();
         $conn->query($query);
         $r = $conn->next();

         if(empty($r)) {
            return;
         }

         $this->parseSqlResult($r);
      }
   }

   public function parseSqlResult($r) {
      if(isset($r["SNA_ID"])) {
      	$this->id = $r["SNA_ID"];
      }

      if(isset($r["SNA_NAME"])) {
   	  $this->name = $r["SNA_NAME"];
      }

      if(isset($r["SNA_PRICE"])) {
         $this->price = $r["SNA_PRICE"];
      }

      if(isset($r["SNA_DESC"])) {
         $this->desc = $r["SNA_DESC"];
      }

      if(isset($r["SNA_POINTS"])) {
         $this->points = $r["SNA_POINTS"];
      }

      if(isset($r["SNA_TYPE"])) {
         $this->type = $r["SNA_TYPE"];
      }
   }
}
?>